/**
 * 自定义
 * */

var apiDomain = '/api/admin';
var adminLogin = 'adminInfo';
var apis = {
    login: { //登录
        method: 'post',
        url: apiDomain + '/login',
    },
    loginlog: { //登录日志
        method: 'post',
        url: apiDomain + '/login/log/index',
    },
    leftMenu: { //左侧菜单
        method: 'post',
        url: apiDomain + '/leftmenu',
    },
    tongji: { //统计
        method: 'post',
        url: apiDomain + '/tongji',
    },
    indexTongji: { //首页统计
        method: 'post',
        url: apiDomain + '/index/kanban',
    },
    caiwuTongji: { //财务统计
        method: 'post',
        url: apiDomain + '/caiwu/kanban',
    },
    actionIndex: { //功能列表
        method: 'post',
        url: apiDomain + '/action/index',
    },
    actionParent: {
        method: 'post',
        url: apiDomain + '/action/parent',
    },
    actionOne: {
        method: 'post',
        url: apiDomain + '/action/one',
    },
    updateRemark: {
        method: 'post',
        url: apiDomain + '/order/updateRemark',
    },
    actionUpdate: {
        method: 'post',
        url: apiDomain + '/action/update',
    },
    adminIndex: { //管理员列表
        method: 'post',
        url: apiDomain + '/admin/index',
    },
    adminOne: {
        method: 'post',
        url: apiDomain + '/admin/one',
    },
    adminSave: {
        method: 'post',
        url: apiDomain + '/admin/save',
    },
    adminPwd: {
        method: 'post',
        url: apiDomain + '/admin/pwd',
    },
    authList: {
        method: 'post',
        url: apiDomain + '/auth/list',
    },
    authModify: {
        method: 'post',
        url: apiDomain + '/auth/modify',
    },
    userOption: { //用户选项
        method: 'post',
        url: apiDomain + '/user/option',
    },
    userdel: { //用户修改
        method: 'post',
        url: apiDomain + '/user/del',
    },
    userIndex: { //用户列表
        method: 'post',
        url: apiDomain + '/user/index',
    },
    userVipModify: { //用户列表
        method: 'post',
        url: apiDomain + '/user/vip/modify',
    },
    userBankList: { //卡号列表
        method: 'post',
        url: apiDomain + '/user/bank/list',
    },
    userBankDefaultModify: { //卡号默认设置
        method: 'post',
        url: apiDomain + '/user/bank/default/modify',
    },
    userTxAuthList: { //提现审核列表
        method: 'post',
        url: apiDomain + '/user/txauth/list',
    },
    userTxAuthModify: { //提现审核更新
        method: 'post',
        url: apiDomain + '/user/txauth/modify',
    },
    userModify: { //用户修改
        method: 'post',
        url: apiDomain + '/user/modify',
    },
    userFxList: { //分销列表
        method: 'post',
        url: apiDomain + '/user/fxlist',
    },
    userTagList: { //标签列表
        method: 'post',
        url: apiDomain + '/user/tag/list',
    },
    userTagAdd: { //标签增加
        method: 'post',
        url: apiDomain + '/user/tag/add',
    },
    userTagDel: { //标签删除
        method: 'post',
        url: apiDomain + '/user/tag/del',
    },
    userOut: { //用户导出
        method: 'post',
        url: apiDomain + '/user/out',
    },
    userRechargeIndex: { //用户充值记录
        method: 'post',
        url: apiDomain + '/user/recharge/index',
    },
    userTixianIndex: { //用户提现记录
        method: 'post',
        url: apiDomain + '/user/tixian/index',
    },
    userOrderIndex: { //用户消费统计
        method: 'post',
        url: apiDomain + '/user/order/index',
    },
    userTraceIndex: { //浏览历史
        method: 'post',
        url: apiDomain + '/user/trace/index',
    },
    userAddressIndex: { //收货地址
        method: 'post',
        url: apiDomain + '/user/address/index',
    },
    userAddressDefault: { //收货地址默认
        method: 'post',
        url: apiDomain + '/user/address/default',
    },
    wxConfigOne: { //微信配置获取
        method: 'post',
        url: apiDomain + '/wx/config/one',
    },
    wxConfigModify: { //微信配置设置
        method: 'post',
        url: apiDomain + '/wx/config/modify',
    },
    levelIndex: { //会员等级
        method: 'post',
        url: apiDomain + '/level/index',
    },
    levelOne: { //会员等级
        method: 'post',
        url: apiDomain + '/level/one',
    },
    levelModify: { //会员等级
        method: 'post',
        url: apiDomain + '/level/modify',
    },
    levelDel: { //会员等级
        method: 'post',
        url: apiDomain + '/level/del',
    },
    xieyiOne: { //用户协议获取
        method: 'post',
        url: apiDomain + '/xieyi/one',
    },
    xieyiModify: { //用户协议设置
        method: 'post',
        url: apiDomain + '/xieyi/modify',
    },
    qyOne: { //用户协议获取
        method: 'post',
        url: apiDomain + '/qy/one',
    },
    qyModify: { //用户协议设置
        method: 'post',
        url: apiDomain + '/qy/modify',
    },
    couponIndex: { //会员劵列表
        method: 'post',
        url: apiDomain + '/coupon/index',
    },
    couponTmpIndex: { //会员劵模板列表
        method: 'post',
        url: apiDomain + '/coupon/tmp/index',
    },
    couponTmpAdd: { //会员劵模板添加
        method: 'post',
        url: apiDomain + '/coupon/tmp/add',
    },
    couponTmpDel: { //会员劵模板删除
        method: 'post',
        url: apiDomain + '/coupon/tmp/del',
    },
    couponTmpOption: { //会员劵模板选项
        method: 'post',
        url: apiDomain + '/coupon/tmp/option',
    },
    couponSwitch: { //会员劵开关
        method: 'post',
        url: apiDomain + '/coupon/switch/one',
    },
    couponSwitchModify: { //会员劵开关
        method: 'post',
        url: apiDomain + '/coupon/switch/modify',
    },
    goodsCateIndex: {
        method: 'post',
        url: apiDomain + '/goods/cate/index',
    },
    goodsCateOption: {
        method: 'post',
        url: apiDomain + '/goods/cate/option',
    },
    goodsCateOne: {
        method: 'post',
        url: apiDomain + '/goods/cate/one',
    },
    goodsCateSave: {
        method: 'post',
        url: apiDomain + '/goods/cate/save',
    },
    goodsCateDel: {
        method: 'post',
        url: apiDomain + '/goods/cate/del',
    },
    goodsCateSel: {
        method: 'post',
        url: apiDomain + '/goods/cateSel',
    },
    goodsCateOut: {
        method: 'post',
        url: apiDomain + '/goods/cate/out',
    },
    imageIndex: { //图片列表
        method: 'post',
        url: apiDomain + '/image/list',
    },
    imageUpload: { //图片上传
        method: 'post',
        url: apiDomain + '/image/upload',
    },
    videoUpload: { //视频上传
        method: 'post',
        url: apiDomain + '/video/upload',
    },
    goodsIndex: { //商品列表
        method: 'post',
        url: apiDomain + '/goods/index',
    },
    GoodsShelfBatch: {
        method: 'post',
        url: apiDomain + '/goods/batchStatus',
    },
    GoodsBatchDel: {
        method: 'post',
        url: apiDomain + '/goods/batchDel',
    },
    goodsOne: {
        method: 'post',
        url: apiDomain + '/goods/one',
    },
    gSkuList: { //SKU列表
        method: 'post',
        url: apiDomain + '/goods/sku/list',
    },
    goodsAdd: {
        method: 'post',
        url: apiDomain + '/goods/add',
    },
    goodsModify: {
        method: 'post',
        url: apiDomain + '/goods/modify',
    },
    goodsDel: {
        method: 'post',
        url: apiDomain + '/goods/del',
    },
    goodsShelf: {
        method: 'post',
        url: apiDomain + '/goods/shelf',
    },
    goodsOut: {
        method: 'post',
        url: apiDomain + '/goods/out',
    },
    goodsMoreUpload: { //详情图上传
        method: 'post',
        url: apiDomain + '/goods/more/upload',
    },
    goodsMoreDel: {
        method: 'post',
        url: apiDomain + '/goods/more/del',
    },
    goodsSkuAdd: { //SKU添加
        method: 'post',
        url: apiDomain + '/goods/sku/add',
    },
    goodsSkuModify: {
        method: 'post',
        url: apiDomain + '/goods/sku/modify',
    },
    goodsSkuDel: {
        method: 'post',
        url: apiDomain + '/goods/sku/del',
    },
    goodsWordList: {
        method: 'post',
        url: apiDomain + '/goods/word/list',
    },
    shopIndex: {
        method: 'post',
        url: apiDomain + '/shop/index',
    },
    shopOne: {
        method: 'post',
        url: apiDomain + '/shop/one',
    },
    shopModify: {
        method: 'post',
        url: apiDomain + '/shop/modify',
    },
    shopDel: {
        method: 'post',
        url: apiDomain + '/shop/del',
    },
    shopAddressToMap: { //地址转坐标
        method: 'post',
        url: apiDomain + '/shop/addresstomap',
    },
    brandIndex: {
        method: 'post',
        url: apiDomain + '/brand/index',
    },
    brandAdd: {
        method: 'post',
        url: apiDomain + '/brand/add',
    },
    brandOne: {
        method: 'post',
        url: apiDomain + '/brand/one',
    },
    brandDel: {
        method: 'post',
        url: apiDomain + '/brand/del',
    },
    brandKg: {
        method: 'post',
        url: apiDomain + '/brand/kg/modify',
    },
    brandTypeSort: {
        method: 'post',
        url: apiDomain + '/brand/type/sort',
    },
    brandSort: {
        method: 'post',
        url: apiDomain + '/brand/sort',
    },
    brandSortModify: {
        method: 'post',
        url: apiDomain + '/brand/sort/modify',
    },
    cartIndex: {
        method: 'post',
        url: apiDomain + '/cart/index',
    },
    orderIndex: {
        method: 'post',
        url: apiDomain + '/order/index',
    },
    orderOne: {
        method: 'post',
        url: apiDomain + '/order/one',
    },
    orderAuth: {
        method: 'post',
        url: apiDomain + '/order/auth',
    },
    orderTuiAuth: {
        method: 'post',
        url: apiDomain + '/order/tuihuo/auth',
    },
    orderSend: {
        method: 'post',
        url: apiDomain + '/order/send',
    },
    orderBatchSend: {
        method: 'post',
        url: apiDomain + '/order/batch/send',
    },
    categories: { //商品列表
        method: 'post',
        url: apiDomain + '/goods/getCategories',
    },
    orderKefu: {
        method: 'post',
        url: apiDomain + '/order/kefu',
    },
    orderOut: {
        method: 'post',
        url: apiDomain + '/order/out',
    },
    //二期发现
    findIndex: {
        method: 'post',
        url: apiDomain + '/find/index',
    },
    findOne: {
        method: 'post',
        url: apiDomain + '/find/one',
    },
    findAuth: {
        method: 'post',
        url: apiDomain + '/find/auth',
    },
    findDel: {
        method: 'post',
        url: apiDomain + '/find/del',
    },
    findTop: {
        method: 'post',
        url: apiDomain + '/find/top/modify',
    },
    findCateList: {
        method: 'post',
        url: apiDomain + '/find/cate/list',
    },
    findCateModify: {
        method: 'post',
        url: apiDomain + '/find/cate/modify',
    },
    findCateDel: {
        method: 'post',
        url: apiDomain + '/find/cate/del',
    },
    findSwitchOne: {
        method: 'post',
        url: apiDomain + '/find/switch/one',
    },
    findSwitchModify: {
        method: 'post',
        url: apiDomain + '/find/switch/modify',
    },
    /**
     * 二期渠道端
     * */
    qdGcateOption: {
        method: 'post',
        url: apiDomain + '/qudao/gcate/option',
    },
    qdGcateIndex: {
        method: 'post',
        url: apiDomain + '/qudao/gcate/index',
    },
    qdGcateModify: {
        method: 'post',
        url: apiDomain + '/qudao/gcate/modify',
    },
    qdGcateDel: {
        method: 'post',
        url: apiDomain + '/qudao/gcate/del',
    },
    qdGcateOut: {
        method: 'post',
        url: apiDomain + '/qudao/gcate/out',
    },
    qdGoodsIndex: {
        method: 'post',
        url: apiDomain + '/qudao/goods/index',
    },
    qdGoodsShelfBatch: {
        method: 'post',
        url: apiDomain + '/qudao/goods/batchStatus',
    },
    qdGoodsBatchDel: {
        method: 'post',
        url: apiDomain + '/qudao/goods/batchDel',
    },
    qdGoodsOne: {
        method: 'post',
        url: apiDomain + '/qudao/goods/one',
    },
    qdGcateList: {
        method: 'post',
        url: apiDomain + '/qudao/goods/catelist',
    },
    qdGoodsAdd: {
        method: 'post',
        url: apiDomain + '/qudao/goods/add',
    },
    qdGoodsModify: {
        method: 'post',
        url: apiDomain + '/qudao/goods/modify',
    },
    qdGoodsDel: {
        method: 'post',
        url: apiDomain + '/qudao/goods/del',
    },
    qdGoodsShelf: {
        method: 'post',
        url: apiDomain + '/qudao/goods/shelf',
    },
    qdGoodsOut: {
        method: 'post',
        url: apiDomain + '/qudao/goods/out',
    },
    qdGmoreUpload: { //详情图上传
        method: 'post',
        url: apiDomain + '/qudao/gmore/upload',
    },
    qdGmoreDel: {
        method: 'post',
        url: apiDomain + '/qudao/gmore/del',
    },
    qdGskuAdd: { //SKU添加
        method: 'post',
        url: apiDomain + '/qudao/gsku/add',
    },
    qdGskuModify: {
        method: 'post',
        url: apiDomain + '/qudao/gsku/modify',
    },
    qdGskuDel: {
        method: 'post',
        url: apiDomain + '/qudao/gsku/del',
    },
    qdGskuList: { //SKU列表
        method: 'post',
        url: apiDomain + '/qudao/gsku/list',
    },
    qdCartIndex: {
        method: 'post',
        url: apiDomain + '/qudao/cart/index',
    },
    qdOrderIndex: {
        method: 'post',
        url: apiDomain + '/qudao/order/index',
    },
    qdOrderOne: {
        method: 'post',
        url: apiDomain + '/qudao/order/one',
    },
    qdOrderAuth: {
        method: 'post',
        url: apiDomain + '/qudao/order/auth',
    },
    qdOrderSend: {
        method: 'post',
        url: apiDomain + '/qudao/order/send',
    },
    qdOrderBatchSend: {
        method: 'post',
        url: apiDomain + '/qudao/order/batch/send',
    },
    qdAcceptIndex: {
        method: 'post',
        url: apiDomain + '/qudao/accept/index',
    },
    qdSucaiIndex: { //素材
        method: 'post',
        url: apiDomain + '/qudao/sucai/index',
    },
    qdSucaiOne: { //素材详情
        method: 'post',
        url: apiDomain + '/qudao/sucai/one',
    },
    qdSucaiModify: { //素材更新
        method: 'post',
        url: apiDomain + '/qudao/sucai/modify',
    },
    qdSucaiUpload: { //素材上传
        method: 'post',
        url: apiDomain + '/qudao/sucai/upload',
    },
    qdSucaiDel: { //素材删除
        method: 'post',
        url: apiDomain + '/qudao/sucai/del',
    },
    qdShopIndex: { //渠道商
        method: 'post',
        url: apiDomain + '/qudao/shop/index',
    },
    qdShopAuth: { //渠道商
        method: 'post',
        url: apiDomain + '/qudao/shop/auth',
    },
    qdShopRechargeList: { //充值记录
        method: 'post',
        url: apiDomain + '/qudao/shop/recharge/list',
    },
    qdShopTixianList: { //提现记录
        method: 'post',
        url: apiDomain + '/qudao/shop/tixian/list',
    },
    qdShopCostList: { //消费记录
        method: 'post',
        url: apiDomain + '/qudao/shop/cost/list',
    },
    qdShopTeamList: { //提现记录
        method: 'post',
        url: apiDomain + '/qudao/shop/team/list',
    },
    qdShopTeamIncomeList: { //收益记录
        method: 'post',
        url: apiDomain + '/qudao/shop/team/income/list',
    },
    qdShopBankList: { //卡号列表
        method: 'post',
        url: apiDomain + '/qudao/shop/bank/list',
    },
    qdShopBankDefaultModify: { //卡号默认设置
        method: 'post',
        url: apiDomain + '/qudao/shop/bank/default/modify',
    },
    qdShopTxAuthList: { //提现审核列表
        method: 'post',
        url: apiDomain + '/qudao/shop/txauth/list',
    },
    qdShopTxAuthModify: { //提现审核更新
        method: 'post',
        url: apiDomain + '/qudao/shop/txauth/modify',
    },
    qdCardOpton: { //卡选项
        method: 'post',
        url: apiDomain + '/qudao/card/option',
    },
    qdCardIndex: { //礼品卡列表
        method: 'post',
        url: apiDomain + '/qudao/card/index',
    },
    qdCardOne: { //礼品卡详情
        method: 'post',
        url: apiDomain + '/qudao/card/one',
    },
    qdCardModify: { //礼品卡修改
        method: 'post',
        url: apiDomain + '/qudao/card/modify',
    },
    qdCardUpload: { //礼品卡上传
        method: 'post',
        url: apiDomain + '/qudao/card/upload',
    },
    qdCardDel: { //礼品卡删除
        method: 'post',
        url: apiDomain + '/qudao/card/del',
    },
    qdCardGoption: { //卡商品
        method: 'post',
        url: apiDomain + '/qudao/card/goods/option',
    },
    qdCardGlist: { //卡商品
        method: 'post',
        url: apiDomain + '/qudao/card/goods/index',
    },
    qdCardGmodify: { //卡商品
        method: 'post',
        url: apiDomain + '/qudao/card/goods/modify',
    },
    qdCardGdel: { //卡商品
        method: 'post',
        url: apiDomain + '/qudao/card/goods/del',
    },
    qdCardOrder: { //卡订单
        method: 'post',
        url: apiDomain + '/qudao/card/order/list',
    },
    qdCardUser: { //卡用户
        method: 'post',
        url: apiDomain + '/qudao/card/user/index',
    },
    qdCcateList: { //卡分类
        method: 'post',
        url: apiDomain + '/qudao/card/cate/list',
    },
    qdCcateModify: { //卡分类
        method: 'post',
        url: apiDomain + '/qudao/card/cate/modify',
    },
    qdCcateDel: { //卡分类
        method: 'post',
        url: apiDomain + '/qudao/card/cate/del',
    },
    qdBannerIndex: { //轮播图
        method: 'post',
        url: apiDomain + '/qudao/banner/index',
    },
    qdBannerAdd: { //轮播图
        method: 'post',
        url: apiDomain + '/qudao/banner/add',
    },
    qdBannerDel: { //轮播图
        method: 'post',
        url: apiDomain + '/qudao/banner/del',
    },
    qdConfigList: { //配置参数
        method: 'post',
        url: apiDomain + '/qudao/config/list',
    },
    //qdConfigModify: { //配置参数
    //    method: 'post',
    //    url: apiDomain + '/qudao/config/modify',
    //},
    //qdConfigModify: { //配置参数
    //    method: 'post',
    //    url: apiDomain + '/qudao/config/modify',
    //},
    qdOrderOut: { //订单导出
        method: 'post',
        url: apiDomain + '/qudao/order/out',
    },
    eqJifen: { //用户积分
        method: 'post',
        url: apiDomain + '/erqi/jifen',
    },
    eqJf2g: { //用户积分
        method: 'post',
        url: apiDomain + '/erqi/jf2g',
    },
    eqJdOrderAuth: { //用户审核
        method: 'post',
        url: apiDomain + '/erqi/jforder/auth',
    },
    eqJdOrderSend: { //用户发货
        method: 'post',
        url: apiDomain + '/erqi/jforder/send',
    },
    eqSign: { //用户签到
        method: 'post',
        url: apiDomain + '/erqi/sign',
    },
    eqCostList: { //费用
        method: 'post',
        url: apiDomain + '/qudao/cost/list',
    },
    eqCostAdd: { //费用
        method: 'post',
        url: apiDomain + '/qudao/cost/add',
    },
    eqCostDel: { //费用
        method: 'post',
        url: apiDomain + '/qudao/cost/del',
    },
    jfGlist: {
        method: 'post',
        url: apiDomain + '/point/goods/index',
    },
    jfGone: {
        method: 'post',
        url: apiDomain + '/point/goods/one',
    },
    jfGcateSel: {
        method: 'post',
        url: apiDomain + '/point/goods/cateSel',
    },
    jfGadd: {
        method: 'post',
        url: apiDomain + '/point/goods/add',
    },
    jfGmodify: {
        method: 'post',
        url: apiDomain + '/point/goods/modify',
    },
    jfGdel: {
        method: 'post',
        url: apiDomain + '/point/goods/del',
    },
    jfGmoreUpload: { //详情图上传
        method: 'post',
        url: apiDomain + '/point/gmore/upload',
    },
    jfGmoreDel: {
        method: 'post',
        url: apiDomain + '/point/gmore/del',
    },
    jfGskuAdd: { //SKU添加
        method: 'post',
        url: apiDomain + '/point/gsku/add',
    },
    jfGskuModify: {
        method: 'post',
        url: apiDomain + '/point/gsku/modify',
    },
    jfGskuDel: {
        method: 'post',
        url: apiDomain + '/point/gsku/del',
    },
    jfGcateOption: {
        method: 'post',
        url: apiDomain + '/point/gcate/option',
    },
    jfGcateIndex: {
        method: 'post',
        url: apiDomain + '/point/gcate/index',
    },
    jfGcateModify: {
        method: 'post',
        url: apiDomain + '/point/gcate/modify',
    },
    jfGcateDel: {
        method: 'post',
        url: apiDomain + '/point/gcate/del',
    },
    //素材中心
    erqiSucaiIndex: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/index',
    },
    erqiSucaiFiles: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/files',
    },
    erqiSucaiOne: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/one',
    },
    erqiSucaiModify: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/modify',
    },
    erqiSucaiDel: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/del',
    },
    erqiSucaiImgUpload: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/upload/img',
    },
    erqiSucaiVideoUpload: {
        method: 'post',
        url: apiDomain + '/erqi/sucai/upload/video',
    },
    //限时折扣
    erqiCheapIndex: {
        method: 'post',
        url: apiDomain + '/erqi/cheap/index',
    },
    erqiCheapModify: {
        method: 'post',
        url: apiDomain + '/erqi/cheap/modify',
    },
    erqiCheapDel: {
        method: 'post',
        url: apiDomain + '/erqi/cheap/del',
    },
};


(function () {
    if (window.location.pathname != '/admin/login.html') {
        header();
        leftMenu();
    }
})();


//顶部header
function header(){
    var adminInfo = getAdminInfo();
    var h = '';
    h += '<style type="text/css"> #apiDoc { color: #fff; cursor: pointer; position: absolute; top: 10px; left: 200px; } #apiDoc:hover { color: #0088cc; } </style>';
    h += '<div class="navbar navbar-fixed-top">';
    h += '<div class="container-fluid cl">';
    h += '<a class="logo navbar-logo f-l mr-10 hidden-xs" href="index.html">';
    h += '仙福缘小程序商城';
    h += '</a>';
    //h += '<nav class="nav navbar-nav">';
    //h += '<ul class="cl">';
    //h += '<li>接口文档</li>';
    //h += '</ul>';
    //h += '</nav>';
    h += '<a href="https://www.eolink.com/share/index?shareCode=a909486f822c1c094b178cf67a7b360c" target="_blank" id="apiDoc">接口文档</a>';
    h += '<nav id="Hui-userbar" class="nav navbar-nav navbar-userbar hidden-xs">';
    h += '<ul class="cl">';
    h += '<li>系统管理员</li>';
    h += '<li class="dropDown dropDown_hover">';
    h += '<a href="javascript:;" class="dropDown_A">';
    h += '<span>' + adminInfo.adminName + '</span> ';
    h += '<i class="Hui-iconfont">&#xe6d5;</i>';
    h += '</a>';
    h += '<ul class="dropDown-menu menu radius box-shadow">';
    h += '<li><a href="javascript:;" onclick="logout();">退出</a></li>';
    h += '</ul>';
    h += '</li>';
    h += '</ul>';
    h += '</nav>';
    h += '</div>';
    h += '</div>';
    h += '';
    $('.navbar-wrapper').html(h);
}


//左侧菜单
function leftMenu(){
    var adminInfo = getAdminInfo();
    console.log(adminInfo);
    if (!adminInfo || !adminInfo.token) {
        layerMsgErr('没有登录');
        setTimeout(function(){
            window.location.href = 'login.html';
        }, 1000);
        return
    }
    $.ajax({
        type: apis.leftMenu.method,
        url: apis.leftMenu.url,
        data: { token: adminInfo.token },
        success: function (res) {
            //console.log(res);
            if (res.code == -3) {
                msgPop({msg: '登录已过期'});
                setTimeout(function(){
                    window.location.href = 'login.html';
                }, 1000);
                return
            }
            if (res.code < 0) {
                console.log(res); return
            }
            leftMenuHtml(res.data);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//菜单字符串
function leftMenuHtml(ms){
    //var ms = [
    //    { id: 1, title: '首页', icon: '&#xe61a;', link: '/admin/index.html', childs: [] },
    //    { id: 2, title: '后台管理', icon: '&#xe62d;', link: '', childs: [
    //        { id: 121, title: '管理员', link: '/admin/admin/admin.html' },
    //        { id: 122, title: '功能表', link: '/admin/admin/action.html' },
    //    ] },
    //    { id: 3, title: '用户管理', icon: '&#xe60d;', link: '', childs: [
    //        { id: 111, title: '用户列表', link: '/admin/user/index.html' },
    //    ] },
    //    { id: 4, title: '商品管理', icon: '&#xe620;', link: '', childs: [
    //        { id: 101, title: '商品列表', link: '/admin/goods/index.html' },
    //        { id: 102, title: '商品分类', link: '/admin/goods/cate.html' },
    //    ] },
    //    { id: 5, title: '购物车', icon: '&#xe620;', link: '/admin/cart.html', childs: [] },
    //    { id: 6, title: '订单管理', icon: '&#xe620;', link: '/admin/order.html', childs: [] },
    //];
    var preUrl = window.location.pathname; //当前相对路径
    var h = '', i;
    h += '<style type="text/css">.mlyjt { ;margin-right: 10px; float: right; } .mla { background: #ffffff; }</style>';
    for (i = 0; i < ms.length; i ++) {
        h += '<dl >';
        if (ms[i].childs.length > 0) {
            h += '<dt onclick="lmQiehuan(' + ms[i].id + ');">';
            h += '<i class="Hui-iconfont">' + ms[i].icon + '</i>';
            h += ' &nbsp;' + ms[i].title;
            h += '<i class="Hui-iconfont menu_dropdown-arrow">&#xe6d5;</i>';
            h += '</dt>';
            h += '</dt>';
        } else {
            if (preUrl == ms[i].link) {
                h += '<a href="' + ms[i].link + '" class="mla">';
            } else {
                h += '<a href="' + ms[i].link + '">';
            }
            h += '<dt>';
            h += '<i class="Hui-iconfont">' + ms[i].icon + '</i>';
            h += ' &nbsp;' + ms[i].title;
            if (preUrl == ms[i].link) {
                h += '<span class="mlyjt">→</span>';
            }
            h += '</dt>';
            h += '</a>';
        }
        h += '<dd style="display: block;" id="lmChild' + ms[i].id + '">';
        if (ms[i].childs.length > 0) {
            h += '<ul>';
            var childs = ms[i].childs;
            for (var ii = 0; ii < childs.length; ii ++) {
                h += '<li>';
                if (preUrl == childs[ii].link) {
                    h += '<a href="' + childs[ii].link + '" class="mla">';
                } else {
                    h += '<a href="' + childs[ii].link + '">';
                }
                h += childs[ii].title;
                if (preUrl == childs[ii].link) {
                    h += '<span class="mlyjt">→</span>';
                }
                h += '</a>';
                h += '</li>';
            }
            h += '</ul>';
        }
        h += '</dd>';
        h += '</dt>';
        h += '';
        h += '</dl>';
    }
    //console.log(h);
    $('#leftMenu').html(h).css('margin-bottom', '50px');
}
//切换菜单
function lmQiehuan(v){
    $('#lmChild' + v).toggle(500);
}


//分页字符串
function pageHtml(e){
    console.log(e);
    var start = e.start, limit = e.limit, total = e.total, url = e.url;
    var pageTotal = Math.ceil(total / limit);
    var h = '';
    h += '<style type="text/css"> #pageHtml {margin: 10px 0; width: 100%; text-align: center; color: #555; } #pageBtn {  color:#555; } #pageBtn a { padding: 5px 10px; color: #0088cc; } </style>';
    h += '显示 <span id="pageCurr">' + start + '</span> / <span id="pageTotal">' + pageTotal + '</span> 页，';
    h += '每页显示';
    h += '<select style="margin: 0 5px; padding: 2px 5px; border: 1px solid #eee;" onchange="listBySel(this.value);">';
    h += '<option value="5"';
    h += pages.limit==5 ? ' selected' : '';
    h += '>5</option>';
    h += '<option value="10"';
    h += pages.limit==10 ? ' selected' : '';
    h += '>10</option>';
    h += '<option value="20"';
    h += pages.limit==20 ? ' selected' : '';
    h += '>20</option>';
    h += '<option value="50"';
    h += pages.limit==50 ? ' selected' : '';
    h += '>50</option>';
    h += '<option value="100"';
    h += pages.limit==100 ? ' selected' : '';
    h += '>100</option>';
    h += '</select>';
    h += '<span id="pageBtn">';
    h += '<a href="javascript:;" onclick="pageHome();">首页</a>';
    h += '<a href="javascript:;" onclick="pagePre();">上一页</a>';
    //h += '<a href="javascript:;" onclick="msgPop({msg: \'当前第' + start + '页\'});">' + start + '</a>';
    h += '<a href="javascript:;" onclick="pageNext();">下一页</a>';
    h += '<a href="javascript:;" onclick="pageEnd();">尾页</a>';
    h += '</span>';
    $('#pageHtml').html(h);
    $('#pageTotal').html(total);
}
function listBySel(v){
    pages.limit = v;
    if (pages.url == '/admin/uctmp.html') {
        getTmpList();
    } else {
        getList();
    }
}
//首页
function pageHome(){
    window.location.href = pages.url;
}
//上一页
function pagePre(){
    var start = pages.start * 1 - 1;
    if (start <= 0) {
        msgPop({msg: '已经是第一页了'});
        return
    }
    //window.location.href = pages.url + '?start=' + start;
    toUrl(start);
}
//下一页
function pageNext(){
    var start = pages.start * 1 + 1;
    var pageTotal = Math.ceil(pages.total / pages.limit);
    console.log(start, pageTotal);
    if (start > pageTotal) {
        msgPop({msg: '已经是最后一页了'});
        return
    }
    //window.location.href = pages.url + '?start=' + start;
    toUrl(start);
}
//尾页
function pageEnd(){
    var pageTotal = Math.ceil(pages.total / pages.limit);
    //window.location.href = pages.url + '?start=' + pageTotal;
    toUrl(pageTotal);
}
//跳转
function toUrl(v){
    var url = pages.url;
    url += '?start=' + v;
    if (pages.url == '/admin/qudao/order.html') {
        url += '&start_day=' + $('#logmin').val();
        url += '&end_day=' + $('#logmax').val();
        url += '&orderno=' + $('#orderno').val();
        url += '&phone=' + $('#phone').val();
    }
    if (pages.url == '/admin/uindex.html') {
        url += '&phone=' + $('#phone').val();
        url += '&nick=' + $('#nick').val();
        url += '&ulevel=' + $('#ulevel').val();
    }
    if (pages.url == '/admin/order.html') {
        url += '&start_day=' + $('#logmin').val();
        url += '&end_day=' + $('#logmax').val();
        url += '&orderno=' + $('#orderno').val();
        url += '&phone=' + $('#phone').val();
    }
    window.location.href = url;
}


//上传HTML
function uploadHtml(type){
    var selid = type==1 ? 'big' : 'more';
    var h = '';
    if (type == 2) {
        h += '<div id="moreDiv">';
    }
    h += '<div style="padding: 5px 0; width: 100px; background: #0088cc; text-align: center; font-size: 12px; color: #fff; border-radius: 5px; position: relative;">上传图片</div>';
    h += '<input type="file" id="' + selid + 'Upload" style="width: 150px; height: 30px; opacity: 0; cursor: pointer; position: relative; top: -25px; left: -20px;" onchange="uploadImage(' + type + ')"/>';
    if (type == 2) {
        h += '</div>';
    }
    h += '<div id="' + selid + 'Show" style="margin-top: -20px; width: 500px; height: 300px; background: #eee; overflow-x: hidden; overflow-y: auto;"></div>';
    $('#' + selid + 'Out').html(h);
}


////抓图
//function uploadImage() {
//    var img = $("#viewimg"), dataURL, fileObj = $('#' + selid + 'Upload')[0],
//        windowURL = window.URL || window.webkitURL, reader = new FileReader();
//    dataURL = windowURL.createObjectURL(fileObj.files[0]); //要显示图片的路径
//    img.attr("src", dataURL); //显示图片
//    reader.readAsDataURL(fileObj.files[0]); //这一步是关键
//    reader.onload = function (e){
//        //console.log(e.target.result);
//        //$('#img')[0].value = e.target.result; //这一步是关键
//        showImg(e.target.result);
//    }
//}


//抓图
function uploadImage(type) {
    var selid = type==1 ? 'big' : 'more';
    if (type == 2 && formData.moreImgs.length >= 5) {
        layer.msg('详情图最多5张',{icon: 0,time: 1000});
        return
    }
    var fileObj = $('#' + selid + 'Upload')[0], reader = new FileReader();
    reader.readAsDataURL(fileObj.files[0]); //这一步是关键
    reader.onload = function (res){
        //console.log(res.target.result);
        imageUpload({type: type, img: res.target.result});
    }
}


//图片上传
function imageUpload(e){
    $.ajax({
        type: apis.imageUpload.method,
        url: apis.imageUpload.url,
        data: { img: e.img },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                layer.msg(res.msg,{icon: 1,time: 1000});
                return
            }
            showImg({type: e.type, domain: res.data.domain, img: res.data.img, w: res.data.w, h: res.data.h});
        },
        error: function () {
            console.log('错误啦！');
        }
    });
}

//图片上传
function uploadVideo(){
    var uploadFile = $("#bigUpload")[0].files[0];
    var formData = new FormData();
    formData.append("video", uploadFile);
    $.ajax({
        type: apis.videoUpload.method,
        url: apis.videoUpload.url,
        data: formData,
        async: false,
        // 下面这两个参数
        processData: false,
        contentType: false,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                layer.msg(res.msg,{icon: 1,time: 1000});
                return
            }
            showVideo(res);
        },
        error: function () {
            console.log('错误啦！');
        }
    });
}


//导出表格
function outExcel(){
    console.log('正在导出...');
    var apiUrl = excelDomain + '/' + pages.excel;
    if (pages.excel = 'user') {
        apiUrl += '?phone=' + $('#phone').val();
        apiUrl += '&nick=' + $('#nick').val();
        apiUrl += '&level=' + $('#ulevel').val();
        window.location.href = apiUrl;
    }
    else if (pages.excel = 'gcate' || pages.excel == 'goods'
            || pages.excel == 'qdcate' || pages.excel == 'qdgoods') {
        window.location.href = apiUrl;
    }
    else if (pages.excel = 'gorder') {
        apiUrl += '?keyword=' + $('#keyword').val();
        apiUrl += '&phone=' + $('#phone').val();
        apiUrl += '&status=' + status;
        apiUrl += '&start_day=' + $('#logmin').val();
        apiUrl += '&end_day=' + $('#logmax').val();
        window.location.href = apiUrl;
    }
    else if (pages.excel = 'qdorder') {
        apiUrl += '?orderno=' + $('#orderno').val();
        apiUrl += '&phone=' + $('#phone').val();
        apiUrl += '&status=' + status;
        apiUrl += '&start_day=' + $('#logmin').val();
        apiUrl += '&end_day=' + $('#logmax').val();
        window.location.href = apiUrl;
    } else {
        msgPop({msg: '导出错误'}); return
    }
    console.log('导出完成');
}


//自定义弹窗
function msgPop(e){
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    var msg = e.msg;
    var h = '';
    h += '<div style="position: fixed; top: 0; left: 0; z-index: 10000;">';
    h += '<div style="width: ' + (cw) + 'px; height: ' + (ch) + 'px; background: #000; opacity: 0.2; position: fixed; top: 0; left: 0; z-index: 10000;"></div>';
    h += '<div style="padding: 10px 20px; width: ' + (cw * 0.5) + 'px; text-align: center; background: #000; color: #FFF; border-radius: 5px; position: fixed; bottom: 20%; left: ' + ((cw * 0.5 - 40) / 2) + 'px; z-index: 10000;">'+msg+'</div>';
    h += '</div>';
    h += '<script>setTimeout(function(){$(\'#msgPop\').html(\'\');},2000)</script>';
    $('#msgPop').html(h);
}


//layer弹窗
function layerMsgErr(e){
    layer.msg(e,{icon: 0,time: 1000});
    return
}


//layer弹窗
function layerMsgOk(e){
    layer.msg(e,{icon: 1,time: 1000});
    return
}


//获取地址栏中参数
function getParamByUrl(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r==null) return '';
    return  unescape(r[2]);
}


//显示前几个字符
function strPrefix(str, limit){
    if (str.length > limit) {
        return str.substring(0, limit) + '...';
    } else {
        return str;
    }
}


//显示后几个字符
function strSuffix(str, limit){
    //console.log(str.length, limit);
    if (str.length > limit) {
        return '...' + str.slice(- limit);
    } else {
        return str;
    }
}


//获取登录信息
function getAdminInfo(){
    return getCache(adminLogin);
}


//设置登录信息
function setAdminInfo(e){
    return setCache({key: adminLogin, val: e.val});
}


//退出登录
function logout(){
    console.log('退出登录');
    delCache({key: adminLogin});
    window.location.href = '/admin/login.html';
}


//设置缓存
function setCache(e){
    var key = e.key, val = JSON.stringify(e.val);
    window.localStorage.setItem(key, val);
}


//获取缓存
function getCache(key){
    var cache = window.localStorage.getItem(key);
    if (!cache) { return ''; }
    return JSON.parse(cache);
}


//删除指定缓存
function delCache(e){
    var key = e.key;
    window.localStorage.removeItem(key);
}


//清理缓存
function clearCache(){
    window.localStorage.clear();
}